package com.netty.common.scanner;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 执行器
 * @author dwjf321
 *
 */
public class Invoker {
	/**
	 * 目标对象
	 */
	private Object target;
	
	/**
	 * 方法
	 */
	private Method method;
	
	
	public static Invoker valueOf(Object target, Method method){
		Invoker invoker = new Invoker();
		invoker.setTarget(target);
		invoker.setMethod(method);
		return invoker;
	}
	
	
	/**
	 * 执行
	 * @param args
	 * @return
	 */
	public void invoke(Object[] args){
		try {
			method.invoke(target, args);
		} catch (IllegalAccessException | IllegalArgumentException
				| InvocationTargetException e) {
			e.printStackTrace();
		}
	}

	public Object getTarget() {
		return target;
	}

	public void setTarget(Object target) {
		this.target = target;
	}

	public Method getMethod() {
		return method;
	}

	public void setMethod(Method method) {
		this.method = method;
	}

}
